package com.dmooo.yxmmerchant.view.model;

import android.content.Context;

import com.common.net.entity.SubjectPost;
import com.common.net.listener.HttpOnNextListener;
import com.common.net.subscribers.ProgressSubscriber;
import com.dmooo.yxmmerchant.http.HttpManager;
import com.dmooo.yxmmerchant.view.contract.ShopPeopleContract;

import java.util.HashMap;
import java.util.Map;

public class ShopPeopleModel implements ShopPeopleContract.ShopPeopleMdl {
    private Context context;
    public ShopPeopleModel(Context context) {
        this.context=context;
    }

    @Override
    public void getGoodsAuth(HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,false,false,"登录中"),map);
        HttpManager.getInstance().getGoodsAuth(post);
    }

    @Override
    public void getServiceAuth(HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,false,false,"登录中"),map);
        HttpManager.getInstance().getServiceAuth(post);
    }

    @Override
    public void getShopAdminList(String token, int page, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("p",page);
        map.put("per",10);
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,false,false,"登录中"),map);
        HttpManager.getInstance().getAdminList(post);
    }

    @Override
    public void delAdmin(String token, String id, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("id",id);
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"登录中"),map);
        HttpManager.getInstance().delAdmin(post);
    }

    @Override
    public void addAdmin(String token, String account, String pwd, String job_num, String truename, String contact, String is_freeze, String auth,String order_rate,String service_order_rate, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("account",account);
        map.put("pwd",pwd);
        map.put("job_num",job_num);
        map.put("truename",truename);
        map.put("contact",contact);
        map.put("is_freeze",is_freeze);
        map.put("auth",auth);
        map.put("order_rate",order_rate);
        map.put("service_order_rate",service_order_rate);
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"登录中"),map);
        HttpManager.getInstance().addAdmin(post);
    }

    @Override
    public void editAdmin(String token, String id, String account, String pwd, String job_num, String truename, String contact, String is_freeze, String auth,String order_rate,String service_order_rate, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("id",id);
        map.put("account",account);
        if(!"".equals(pwd)){
            map.put("pwd",pwd);
        }
        map.put("job_num",job_num);
        map.put("truename",truename);
        map.put("contact",contact);
        map.put("is_freeze",is_freeze);
        map.put("auth",auth);
        map.put("order_rate",order_rate);
        map.put("service_order_rate",service_order_rate);
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"登录中"),map);
        HttpManager.getInstance().editAdmin(post);
    }
}
